package com.efesco.service.zhongheInsure;

import java.util.List;

import com.bstek.dorado.common.*;
import com.bstek.dorado.data.*;
import com.bstek.dorado.data.db.DBStatement;
import com.bstek.dorado.utils.variant.VariantSet;
import com.bstek.dorado.view.*;
import com.bstek.dorado.view.data.*;
import com.bstek.dorado.view.control.*;
import com.efesco.system.User;

/**
 * applyFormViewModel
 */
public class applyFormViewModel extends DefaultViewModel {
  protected void doUpdateData(ParameterSet parameters)
      throws Exception {
	  DoradoContext context = DoradoContext.getContext();
		User user = (User) context.getAttribute(context.SESSION, "User");
	  Dataset ds = getDataset("dataset_apply_form");
	  DBStatement dbs = new DBStatement();
	  dbs.setSql("select zonghe_manage_id,status from " +
	  		"zonghe_manage where employee_id="+ds.getValue("employee_id")+" and employee_on_off_id="+ds.getValue("EMPLOYEE_ON_OFF_ID") +
	  		"and in_char_id="+ds.getValue("IN_CHAR_ID"));
	  List list=dbs.queryForList();
	  if(list.size()==0){
		  dbs.setSql("insert into s_zhonghe_manage (zhonghe_manage_id,employee_id,employee_on_off_id,status,apply_man,apply_date,in_char_id,transact_side) values(general.nextval," +
				  ds.getValue("EMPLOYEE_ID")+","+ds.getValue("EMPLOYEE_ON_OFF_ID")+",1,"+user.getUserId()+",sysdate,"+ds.getValue("IN_CHAR_ID")+","+ds.getValue("TRANSACT_SIDE")+")");
		  dbs.execute();
		  return;
	  }
	  VariantSet rs = (VariantSet) list.get(0);
	  if(rs.getString("STATUS").equals("2")){
		  dbs.setSql("update s_zhonghe_manage set transact_side=3,status=1 " +
		  		"where status=2 and EMPLOYEE_ID="+ds.getValue("EMPLOYEE_ID")+" and EMPLOYEE_ON_OFF_ID="+ds.getValue("EMPLOYEE_ON_OFF_ID")+" and IN_CHAR_ID="+ds.getValue("IN_CHAR_ID"));
		  dbs.execute();
	  }
	  dbs.close();
  //  super.doUpdateData(parameters);
  }

}
